import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import '../widgets/AppColors.dart';

class RepairItem extends StatelessWidget {
  final Map<String, dynamic> data;
  const RepairItem({super.key, required this.data});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(10.0),
      margin: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8.0), // 圆角边框
        color: AppColors.cardColor, // 背景色
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Column(
            children: [
              const SizedBox(
                width: 68,
                height: 68,
                child: Image(
                    image: AssetImage('assets/images/setting/user_logo.png')),
              ),
              Text(
                data['nickName'],
                style: TextStyle(fontSize: 22, color: AppColors.textPrimary),
                textAlign: TextAlign.center,
              ),
              Text(
                data['roleName'],
                style: TextStyle(fontSize: 13, color: AppColors.textSecondary),
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: 10),
              GestureDetector(
                onTap: () async {
                  String phone = data['phonenumber'];
                  final phoneNumber = Uri.parse('tel:+$phone');
                  if (await canLaunchUrl(phoneNumber)) {
                    await launchUrl(phoneNumber);
                  } else {
                    throw 'Could not launch $phoneNumber';
                  }
                },
                child: Image(
                    image: AssetImage('assets/images/setting/call_phone.png')),
              ),
            ],
          ),
        ],
      ),
    );
  }

  Future<bool> canLaunchUrl(Uri url) async {
    return await launchUrl(url, mode: LaunchMode.externalApplication);
  }
}
